package ui;

import java.awt.BorderLayout;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * This panel mimics the layout of the recommendation form.  It can double
 * as a form to fill out, and as a display for previously submitted forms.
 * 
 * @author Aaron Chen
 * @version 3/6/2014
 */
@SuppressWarnings("serial")
public class RecommendationPanel extends AbstractForm {
  
  /** The text field for the Subprogram Chair's name. */
  private JTextField my_tf_spc;
  
  /** The text field for the conference that the manuscript is associated
   * with. */
  private JTextField my_tf_conference_name;
  
  /** The text field for the manuscript's author. */
  private JTextField my_tf_manuscript_author;
  
  /** The text field for the manuscript's title. */
  private JTextField my_tf_manuscript_title;
  
  /** The radio button group for the recommendation summary. */
  private ButtonGroup my_group_summary;
  
  /** The text area for the Subprogram Chair's rationale for his summary rating. */
  private JTextArea my_ta_rationale;


  /**
   * {@inheritDoc}
   */
  @Override
  protected String getFormTitle() {
    return "Recommendation Form";
  }

  /**
   * {@inheritDoc}
   */
  @Override
  protected JPanel createFormPanel() {
    final JPanel panel_form = new JPanel();
    panel_form.setLayout(new BoxLayout(panel_form, BoxLayout.Y_AXIS));
    panel_form.setBackground(Standards.COLOR_BACKGROUND);
    panel_form.setBorder(Standards.BORDER_COMPOUND_FORM);
    
    panel_form.add(createColumnedPanel());
    panel_form.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));

    my_group_summary = new ButtonGroup();
    panel_form.add(createRadioButtonQuestion("Summary", my_group_summary));
    
    panel_form.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    
    final JPanel panel_rationale = new JPanel();
    panel_rationale.setBackground(Standards.COLOR_BACKGROUND);
    panel_form.add(panel_rationale);
    panel_rationale.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_rationale = new JLabel("Rationale");
    panel_rationale.add(lbl_rationale, BorderLayout.CENTER);
    
    my_ta_rationale = new JTextArea();
    my_ta_rationale.setToolTipText("This helps the Program Chair know how "
                                   + "you came to your conclusion.");
    my_ta_rationale.setWrapStyleWord(true);
    my_ta_rationale.setRows(Standards.TEXT_AREA_LARGE_ROWS);
    my_ta_rationale.setLineWrap(true);
    
    panel_rationale.add(createScrollPane(my_ta_rationale), BorderLayout.SOUTH);
    
    return panel_form;
  }
  
  /**
   * Creates the columned portion of the form panel.
   * @return The columned panel.
   */
  private JPanel createColumnedPanel() {
    final JPanel panel_column_split = new JPanel();
    panel_column_split.setBackground(Standards.COLOR_BACKGROUND);
    panel_column_split.setLayout(new BoxLayout(panel_column_split, BoxLayout.X_AXIS));

    panel_column_split.add(createLeftColumnPanel());
    panel_column_split.add(Box.createHorizontalStrut(Standards.STRUT_LENGTH_LARGE));
    panel_column_split.add(createRightColumnPanel());
    
    return panel_column_split;
  }
  
  /**
   * Creates the left column of the columned panel.
   * @return The left column panel.
   */
  private JPanel createLeftColumnPanel() {
    final JPanel panel_left_column = new JPanel();
    panel_left_column.setBackground(Standards.COLOR_BACKGROUND);
    panel_left_column.setLayout(new BoxLayout(panel_left_column, BoxLayout.Y_AXIS));
    
    final JPanel panel_spc_name = new JPanel();
    panel_spc_name.setBackground(Standards.COLOR_BACKGROUND);
    panel_spc_name.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_spc_name = new JLabel("Subprogram Chair Name");
    
    my_tf_spc = new JTextField();
    my_tf_spc.setColumns(Standards.TEXT_BOX_HALF_WIDTH);
    
    final JPanel panel_manuscript_author = new JPanel();
    panel_manuscript_author.setBackground(Standards.COLOR_BACKGROUND);
    panel_manuscript_author.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_manuscript_author = new JLabel("Manuscript Author");
    
    my_tf_manuscript_author = new JTextField();
    my_tf_manuscript_author.setColumns(Standards.TEXT_BOX_HALF_WIDTH);
    
    panel_left_column.add(panel_spc_name);
    panel_spc_name.add(lbl_spc_name, BorderLayout.CENTER);
    panel_spc_name.add(my_tf_spc, BorderLayout.SOUTH);
    panel_left_column.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    panel_left_column.add(panel_manuscript_author);
    panel_manuscript_author.add(lbl_manuscript_author, BorderLayout.CENTER);
    panel_manuscript_author.add(my_tf_manuscript_author, BorderLayout.SOUTH);
    
    return panel_left_column;
  }
  
  /**
   * Creates the right column of the columned panel.
   * @return The right column panel.
   */
  private JPanel createRightColumnPanel() {
    final JPanel panel_right_column = new JPanel();
    panel_right_column.setBackground(Standards.COLOR_BACKGROUND);
    panel_right_column.setLayout(new BoxLayout(panel_right_column, BoxLayout.Y_AXIS));
    
    final JPanel panel_conference = new JPanel();
    panel_conference.setBackground(Standards.COLOR_BACKGROUND);
    panel_conference.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_conference_name = new JLabel("Conference Name");
    
    my_tf_conference_name = new JTextField();
    my_tf_conference_name.setColumns(Standards.TEXT_BOX_HALF_WIDTH);
    
    final JPanel panel_manuscript_title = new JPanel();
    panel_manuscript_title.setBackground(Standards.COLOR_BACKGROUND);
    panel_manuscript_title.setLayout(new BorderLayout(0, 0));
    
    final JLabel lbl_manuscript_title = new JLabel("Manuscript Title");
    
    my_tf_manuscript_title = new JTextField();
    my_tf_manuscript_title.setColumns(Standards.TEXT_BOX_HALF_WIDTH);

    panel_right_column.add(panel_conference);
    panel_conference.add(lbl_conference_name, BorderLayout.CENTER);
    panel_conference.add(my_tf_conference_name, BorderLayout.SOUTH);
    panel_right_column.add(Box.createVerticalStrut(Standards.STRUT_LENGTH_MEDIUM));
    panel_right_column.add(panel_manuscript_title);
    panel_manuscript_title.add(lbl_manuscript_title, BorderLayout.CENTER);
    panel_manuscript_title.add(my_tf_manuscript_title, BorderLayout.SOUTH);
    
    return panel_right_column;
  }
  
}
